export default {
  name: 'CountDown',
  data() {
    return {
      timer: null,
      count: 60,
      isSend: false
    }
  },
  computed: {
    sendBtnText() {
      if (this.isSend) {
        return this.count + 's'
      } else {
        return '获取验证码'
      }
    }
  },
  beforeDestroy() {
    clearInterval(this.timer)
  },
  methods: {
    countDownFn() {
      this.timer = setInterval(() => {
        this.count--
        this.isSend = true

        if (this.count === 0) {
          this.isSend = false
          this.count = 60
          clearInterval(this.timer)
        }
      }, 1000)
    }
  }
}
